<!-- eslint-disable vue/no-use-v-if-with-v-for -->
<template>
	<el-card>
		<el-table v-loading="state.dataListLoading" :data="dataList" stripe @selection-change="selectionChangeHandle">
			<el-table-column type="index" label="序号" header-align="center" align="center" width="60"></el-table-column>
			<el-table-column prop="name" label="分类名称" header-align="center" align="center" min-width="220"></el-table-column>
			<el-table-column v-for="(item, index) in columnList" :key="index" :label="item.label" :prop="item.prop" header-align="center" align="center">
				<el-table-column
					v-for="(child, i) in item.children"
					v-if="item.children.length > 0"
					:key="i"
					:prop="child.prop"
					:label="child.label"
					iheader-align="center"
					align="center"
					width="110"
				></el-table-column>
			</el-table-column>
		</el-table>
	</el-card>
</template>
<script setup lang="ts">
import { GetTotalListApi } from '@/api/standard/maintenance'
import { onMounted, reactive, ref } from 'vue'
const state = reactive({
	queryForm: {
		date: '',
		unit: '',
		no: ''
	},
	pageNum: 1,
	pageSize: 10,
	total: 1,
	dataListLoading: false
})
const columnList = ref([])
const dataList = ref([])

const getDataList = () => {
	state.dataListLoading = true
	GetTotalListApi().then(res => {
		state.dataListLoading = false
		const { data } = res
		const childNum = (data.columnLength - 1) / (data.standardLevelNames.length - 1)
		let childrenList = []
		for (let i = 0; i < data.standardLevelNames.length; i++) {
			columnList.value.push({
				label: data.standardLevelNames[i],
				prop: `val${i}`,
				children: []
			})
			if (i < data.standardLevelNames.length - 1) {
				for (let j = 0; j < childNum; j++) {
					columnList.value[i].children.push({
						label: data.finalStandardStatusNames[j],
						prop: `val${i}${j}`
					})
					childrenList.push({
						label: data.finalStandardStatusNames[j],
						prop: `val${i}${j}`
					})
				}
			}
			if (i == data.standardLevelNames.length - 1) {
				childrenList.push({
					label: data.standardLevelNames[i],
					prop: `val${i}`
				})
			}
		}
		for (let i = 0; i < data.rowLength; i++) {
			dataList.value.push({
				name: data.standardTypeNames[i]
			})
		}
		data.values.forEach((item, index) => {
			item.forEach((val, i) => {
				dataList.value[index][childrenList[i].prop] = val
			})
		})
	})
}

const reset = () => {}

const addOrUpdateHandle = () => {}
const deleteBatchHandle = () => {}
const selectionChangeHandle = () => {}
const sizeChangeHandle = () => {}
const currentChangeHandle = () => {}
const getDataListParent = () => {}

onMounted(() => {
	getDataList()
})
</script>
